package com.zk.yygh.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zk.yygh.dict_client.service.DictFeignClient;
import com.zk.yygh.enums.DictEnum;
import com.zk.yygh.model.user.Patient;
import com.zk.yygh.user.mapper.PatientMapper;
import com.zk.yygh.user.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 张凯
 * @date: 2022/6/17 - 18:40
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Autowired
    private DictFeignClient dictFeignClient;

    @Override
    public List<Patient> getPatientList(Long userId) {
        //查询登录用户下属的就诊人
        List<Patient> patientList = this.baseMapper.selectList(new QueryWrapper<Patient>().eq("user_id", userId));
        //填充下属的就诊相关信息
        patientList.stream().forEach(item->{
            this.packPatient(item);
        });
        return patientList;
    }

    private void packPatient(Patient patient) {
        //根据证件类型编码，获取证件类型具体指
        String certificatesTypeString =
                dictFeignClient.getNameByDictCodeAndValue(DictEnum.CERTIFICATES_TYPE.getDictCode(), Integer.parseInt(patient.getCertificatesType()));//联系人证件
        //联系人证件类型
        String contactsCertificatesTypeString =
                dictFeignClient.getNameByDictCodeAndValue(DictEnum.CERTIFICATES_TYPE.getDictCode(),Integer.parseInt(patient.getContactsCertificatesType()));
        //省
        String provinceString = dictFeignClient.getNameByDictCodeAndValue(Integer.parseInt(patient.getProvinceCode()));
        //市
        String cityString = dictFeignClient.getNameByDictCodeAndValue(Integer.parseInt(patient.getCityCode()));
        //区
        String districtString = dictFeignClient.getNameByDictCodeAndValue(Integer.parseInt(patient.getDistrictCode()));
        patient.getParam().put("certificatesTypeString", certificatesTypeString);
        patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        patient.getParam().put("provinceString", provinceString);
        patient.getParam().put("cityString", cityString);
        patient.getParam().put("districtString", districtString);
        patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());
        return ;
    }
}
